//
//  LastVC.m
//  OpenEyes
//
//  Created by dllo on 15/9/15.
//  Copyright (c) 2015年 dllo. All rights reserved.
//

#import "LastVC.h"
#import "LastView.h"
#import "LastModel.h"
#import "BuyVC.h"
#import "MorePicVC.h"
@interface LastVC ()<requestDelegate,pushControllerDelegate,pushToMoreDelegate>

@property (nonatomic, strong) LastView *lastView;

@property (nonatomic, strong) NSMutableArray *array;

@property (nonatomic, strong) MBProgressHUD *HUD;

@property (nonatomic ,strong)NSTimer *mytimer;
/**
 *  所有图片数组
 */
@property (nonatomic, strong) NSArray *picArray;

@end

@implementation LastVC


-(void)viewWillAppear:(BOOL)animated
{
    self.tabBarController.tabBar.hidden = YES;
    //开启定时器
    [self.mytimer setFireDate:[NSDate distantPast]];

}


-(void)viewWillDisappear:(BOOL)animated
{
    self.tabBarController.tabBar.hidden = NO;
    //关闭定时器
    [self.mytimer setFireDate:[NSDate distantFuture]];
}

- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.array = [NSMutableArray array];
    self.picArray = [NSArray array];
    self.navigationItem.title = @"详情";
    
    
    self.lastView = [[LastView alloc]initWithFrame:self.view.frame];
    [self.view addSubview:self.lastView];
    self.lastView.delegate = self;
    self.lastView.morePicDelegate = self;
    
    
    
    NSString *url = @"token=ARk6MCqumCVjvSM1yEuacwNu549OA7hujzU%3D";
    [[HttpRequest httpRequestHandle]loadRequestWithUrl:@"http://lab.daigj.com/api/ios/hm/detail" method:@"POST" pramar:[NSString stringWithFormat:@"version=1.0.3&%@&id=%@",url,self.getId]];
    [HttpRequest httpRequestHandle].delegate = self;
  
    
// 菊花
    self.HUD = [MBProgressHUD showHUDAddedTo:self.view animated:YES];
    self.HUD.removeFromSuperViewOnHide = YES;
    self.HUD.labelText = @"loading.....";
    [self.view addSubview:self.HUD];
    self.HUD.mode = MBProgressHUDModeIndeterminate;
    

    
    self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithImage:[[UIImage imageNamed:@"fanhui-3.png"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal] style:UIBarButtonItemStyleDone target:self action:@selector(left)];
    
    
    //定时器
    self.mytimer = [NSTimer scheduledTimerWithTimeInterval:20 target:self selector:@selector(Timer) userInfo:nil repeats:YES];

    
}
//计时器方法
-(void)Timer{
    
    [UIView animateWithDuration:10 animations:^{
        self.lastView.img.transform = CGAffineTransformScale( self.lastView.img.transform, 1.2, 1.2);
        
    } completion:^(BOOL finished) {
        
        [UIView animateWithDuration:10 animations:^{
             self.lastView.img.transform = CGAffineTransformScale( self.lastView.img.transform,1/1.2, 1/1.2);
        } completion:^(BOOL finished) {
            
           // NSLog(@"123");
            return ;
            
        }];
    }];
    
    
    
}
-(void)left{
    [self.navigationController popViewControllerAnimated:YES];
}





-(void)requestData:(id)data
{
//    NSLog(@"%@",data);
    NSDictionary *detailDic = data [@"data"] [@"detail"];
    LastModel *model = [[LastModel alloc]init];
    [model setValuesForKeysWithDictionary:detailDic];

    [self.array addObject:model];
    [self.HUD setHidden:YES];
    [self.lastView getValue:model];

    
}



-(void)push:(BuyVC *)controller
{

    [self.navigationController pushViewController:controller animated:YES];
}

-(void)pushTo:(MorePicVC *)controller
{
//    [self.navigationController pushViewController:controller animated:YES];
    [self presentViewController:controller animated:nil completion:nil];
}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
